import { defineStore } from 'pinia';
import { ref } from 'vue';
import {
  GET_AMOUNT_LIST_DATA,
  GET_GOODS_ADDRESS_SALE,
  GET_GOODS_CATEGORY_COUNT,
  GET_GOODS_CATEGORY_FAVOR,
  GET_GOODS_CATEGORY_SALE
} from '@/api/main/analysis';

const useAnalysisStore = defineStore('analysis', () => {
  const stateAmountList = ref<any[]>();
  const stateGoodsCategoryCount = ref<any[]>();
  const stateGoodsCategorySale = ref<any[]>();
  const stateGoodsCategoryFavor = ref<any[]>();
  const stateGoodsAddressSale = ref<any[]>();

  function fetchAnalysisDataAction() {
    GET_AMOUNT_LIST_DATA()
      .then((res) => {
        stateAmountList.value = res;
      })
      .catch((err) => {
        console.warn(err);
      });
    GET_GOODS_CATEGORY_COUNT()
      .then((res) => {
        stateGoodsCategoryCount.value = res;
      })
      .catch((err) => {
        console.warn(err);
      });
    GET_GOODS_CATEGORY_SALE()
      .then((res) => {
        stateGoodsCategorySale.value = res;
      })
      .catch((err) => {
        console.warn(err);
      });
    GET_GOODS_CATEGORY_FAVOR()
      .then((res) => {
        stateGoodsCategoryFavor.value = res;
      })
      .catch((err) => {
        console.warn(err);
      });
    GET_GOODS_ADDRESS_SALE()
      .then((res) => {
        stateGoodsAddressSale.value = res;
      })
      .catch((err) => {
        console.warn(err);
      });
  }

  return {
    stateAmountList,
    stateGoodsCategoryCount,
    stateGoodsCategorySale,
    stateGoodsCategoryFavor,
    stateGoodsAddressSale,
    fetchAnalysisDataAction
  };
});

export default useAnalysisStore;
